
package client;



import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import handling.world.WorldBroadcastService;
 import handling.world.WorldFindService;
 import scripting.lieDetector.LieDetectorScript;
 import server.Timer;
 import server.maps.MapleMap;
 import server.quest.MapleQuest;
 import tools.HexTool;
 import tools.MaplePacketCreator;
 import tools.Pair;








 public class MapleLieDetector
         {
       public final int chrid;
       public byte type;
       public int attempt;
       public String tester;
       public String answer;
       public boolean inProgress;
       public boolean passed;



    @JsonCreator
     public MapleLieDetector(@JsonProperty("chrid") int chrid) {
        /*  33 */
        this.chrid = chrid;
        /*  34 */
        reset();

    }



    public final boolean startLieDetector(String tester, boolean isItem, boolean anotherAttempt) {
        /*  38 */
        if (!anotherAttempt && ((isPassed() && isItem) || inProgress() || this.attempt == 3))
             {

            /*  41 */
            return false;

        }
        /*  43 */
        Pair<String, String> captcha = LieDetectorScript.getImageBytes();
        /*  44 */
        if (captcha == null) {
            /*  45 */
            return false;

        }
        /*  47 */
        byte[] image = HexTool.getByteArrayFromHexString((String) captcha.getLeft());
        /*  48 */
        this.answer = (String) captcha.getRight();
        /*  49 */
        this.tester = tester;
        /*  50 */
        this.inProgress = true;
        /*  51 */
        this.type = (byte) (isItem ? 0 : 1);
        /*  52 */
        this.attempt++;

        /*  54 */
        MapleCharacter chr = WorldFindService.getInstance().findCharacterById(this.chrid);
        /*  55 */
        if (chr == null) {
            /*  56 */
            return false;

        }
        /*  58 */
        chr.send(MaplePacketCreator.sendLieDetector(image, this.attempt));
        /*  59 */
        Timer.EtcTimer.getInstance().schedule(() -> {
            if (!isPassed()) if (this.attempt >= 3) {
                MapleCharacter search_chr = chr.getMap().getCharacterByName(tester);
                if (search_chr != null && search_chr.getId() != chr.getId()) {
                    search_chr.dropMessage(5, chr.getName() + " 没用通过测谎仪的检测，恭喜你获得7000的金币.");
                    search_chr.gainMeso(7000L, true);
                }
                end();
                chr.send(MaplePacketCreator.LieDetectorResponse((byte) 10, (byte) 4));
                MapleMap map = chr.getClient().getChannelServer().getMapFactory().getMap(180000001);
                chr.getQuestNAdd(MapleQuest.getInstance(123456)).setCustomData(String.valueOf(1800));
                chr.changeMap(map, map.getPortal(0));
                WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + chr.getName() + " (等级 " + chr.getLevel() + ") 未通过测谎仪检测，系统将其监禁30分钟！"));
            } else {
                startLieDetector(tester, isItem, true);
            }
        }, 60000L);


















        /*  78 */
        return true;

    }



    public final int getAttempt() {
        /*  82 */
        return this.attempt;

    }



    public final byte getLastType() {
        /*  86 */
        return this.type;

    }



    public final String getTester() {
        /*  90 */
        return this.tester;

    }



    public final String getAnswer() {
        /*  94 */
        return this.answer;

    }



    public final boolean inProgress() {
        /*  98 */
        return this.inProgress;

    }



    public final boolean isPassed() {
        /* 102 */
        return this.passed;

    }



    public final void end() {
        /* 106 */
        this.inProgress = false;
        /* 107 */
        this.passed = true;
        /* 108 */
        this.attempt = 0;

    }



    public final void reset() {
        /* 112 */
        this.tester = "";
        /* 113 */
        this.answer = "";
        /* 114 */
        this.attempt = 0;
        /* 115 */
        this.inProgress = false;
        /* 116 */
        this.passed = false;

    }

}


/* Location:              C:\PGX\Server.jar!\client\MapleLieDetector.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */